package core.validate.rules;

import core.validate.RuleTest;
import core.validate.StringRule;

import java.util.List;

public enum StringType {
    CONTAIN, LENGTH, MAX, MIN, BETWEEN,
    START_WITH, END_WITH, NOT_START_WITH, NOT_END_WITH,
    LOWER, UPPER, URL, PATH,
    TEST, REGEX, NOT_REGEX, IN, NOT_IN, EMPTY;

    public void apply(StringRule rule, List<Object> params, String message) {
        switch (this) {
            case CONTAIN -> rule.contain((String) params.get(0), message);
            case LENGTH -> rule.length((Integer) params.get(0), message);
            case MAX -> rule.max((Integer) params.get(0), message);
            case MIN -> rule.min((Integer) params.get(0), message);
            case BETWEEN -> rule.between((Integer) params.get(0), (Integer) params.get(1), message);
            case START_WITH -> rule.startWith((String) params.get(0), message);
            case END_WITH -> rule.endWith((String) params.get(0), message);
            case NOT_START_WITH -> rule.notStartWith((String) params.get(0), message);
            case NOT_END_WITH -> rule.notEndWith((String) params.get(0), message);
            case LOWER -> rule.lower(message);
            case UPPER -> rule.upper(message);
            case URL -> rule.url(message);
            case PATH -> rule.path(message);
            case TEST -> rule.test((RuleTest) params.get(0), message);
            case REGEX -> rule.regex((String) params.get(0), message);
            case NOT_REGEX -> rule.notRegex((String) params.get(0), message);
            case IN -> rule.in((Object[]) params.get(0), message);
            case NOT_IN -> rule.notIn((Object[]) params.get(0), message);
        }
    }
}
